package com.xiaolei.library.Utils;


/**
 * 自定义的日志类
 */
public class Log
{
    public static boolean DEBUG = true;

    /**
     * 校验日志Tag的合理性
     *
     * @param tag 日志的TAG
     */
    private static void checkTag(String tag) throws IllegalStateException
    {
        if (tag == null
                || tag.isEmpty()
                || tag.startsWith("HTC_RIL")
                || tag.startsWith("RIL")
                || tag.startsWith("IMS")
                || tag.equals("AT")
                || tag.equals("GSM")
                || tag.equals("STK")
                || tag.equals("CDMA")
                || tag.equals("PHONE")
                || tag.equals("SMS")
        ) throw new IllegalStateException("LogCat Tag Can not be KeyWord--" + tag);
    }

    public synchronized static void i(String tag, Object obj, Throwable throwable)
    {
        checkTag(tag);
        if (DEBUG) android.util.Log.i(tag, String.valueOf(obj), throwable);
    }

    public synchronized static void i(String tag, String format, Object... args)
    {
        checkTag(tag);
        if (DEBUG) android.util.Log.i(tag, String.format(format, args));
    }

    public synchronized static void i(String tag, Object obj)
    {
        checkTag(tag);
        if (DEBUG) android.util.Log.i(tag, String.valueOf(obj));
    }


    public synchronized static void e(String tag, Object obj, Throwable throwable)
    {
        checkTag(tag);
        if (DEBUG) android.util.Log.e(tag, String.valueOf(obj), throwable);
    }

    public synchronized static void e(String tag, String format, Object... args)
    {
        checkTag(tag);
        if (DEBUG) android.util.Log.e(tag, String.format(format, args));
    }

    public synchronized static void e(String tag, Object obj)
    {
        checkTag(tag);
        if (DEBUG) android.util.Log.e(tag, String.valueOf(obj));
    }


    public synchronized static void v(String tag, Object obj, Throwable throwable)
    {
        checkTag(tag);
        if (DEBUG) android.util.Log.v(tag, String.valueOf(obj), throwable);
    }

    public synchronized static void v(String tag, String format, Object... args)
    {
        checkTag(tag);
        if (DEBUG) android.util.Log.v(tag, String.format(format, args));
    }

    public synchronized static void v(String tag, Object obj)
    {
        checkTag(tag);
        if (DEBUG) android.util.Log.v(tag, String.valueOf(obj));
    }


    public synchronized static void w(String tag, Object obj, Throwable throwable)
    {
        checkTag(tag);
        if (DEBUG) android.util.Log.w(tag, String.valueOf(obj), throwable);
    }

    public synchronized static void w(String tag, String format, Object... args)
    {
        checkTag(tag);
        if (DEBUG) android.util.Log.w(tag, String.format(format, args));
    }

    public synchronized static void w(String tag, Object obj)
    {
        checkTag(tag);
        if (DEBUG) android.util.Log.w(tag, String.valueOf(obj));
    }


    public synchronized static void d(String tag, Object obj, Throwable throwable)
    {
        checkTag(tag);
        if (DEBUG) android.util.Log.d(tag, String.valueOf(obj), throwable);
    }

    public synchronized static void d(String tag, String format, Object... args)
    {
        checkTag(tag);
        if (DEBUG) android.util.Log.d(tag, String.format(format, args));
    }

    public synchronized static void d(String tag, Object obj)
    {
        checkTag(tag);
        if (DEBUG) android.util.Log.d(tag, String.valueOf(obj));
    }
}
